﻿@inject FwProject.Shop.Views.WebRootUrl WebRootUrl
@{
    ViewBag.Title = "优惠券列表";
}
@section styles{
    @*<link href="~/static/css/Ztree.css" type="text/css" rel="stylesheet" />
        <link href="~/static/css/metroStyle.css" type="text/css" rel="stylesheet" />
        <link href="~/static/css/public.css" type="text/css" rel="stylesheet" />*@
    <link href="~/static/css/client.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/system.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/contract.css" type="text/css" rel="stylesheet" />
}
<style>
    a {
        text-decoration: none;
    }

    .hidden {
        display: none;
    }
</style>
<div class="layui-fluid layui-content">
    <div class="layui-title layui-clear layui-row">
        <h2 class="layui-col-md10 layui-col-sm9 layui-col-xs7">@ViewBag.Title</h2>
        <div class="layui-col-md2 layui-col-sm3 layui-col-xs5 layui-nav-item">
            <a class="layui-btn layui-btn-xs" onclick="LayerOpen('添加优惠券','@Url.Action("Create")')">添加优惠券</a>
        </div>
    </div>
    <div class="layui-data layui-table-container" style="margin-top: 15px;">
        <table class="layui-hide layui-table" id="layui-table" lay-filter="table"></table>
    </div>
</div>
<div id="Layer_ajax" class="deploy-plus"></div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="issue">发放</a>
    <a class="layui-btn layui-btn-xs" lay-event="examine">使用查看</a>
    {{#  if(d.couponCount==0){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}
</script>

@section scripts{

    <script src="~/static/js/jquery.ztree.core.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.excheck.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.exedit.js" type="text/javascript"></script>
    <script src="~/js/main.js"></script>

    <script type="text/javascript">

        var layer,form, table, upload;
        layui.use(['form', 'layedit', 'laydate', 'tree', 'table', 'layer', 'upload'], function () {
            var /*form = layui.form*/
                layedit = layui.layedit
                , laydate = layui.laydate;

            layer = layui.layer
            upload = layui.upload;
            form = layui.form;
            table = layui.table;

            table.render({
                elem: "#layui-table",
                url: '/Coupon/GetShopCouponData',
                cellMinWidth: 26,
                height: 'full-150',
                cols: [[
                    //{ type: 'checkbox' },
                    { field: 'couponTitile', title: '优惠券名称'},
                    {
                        field: 'couponType', title: '使用类别', templet: function (d) {
                            if (d.couponType=="0") {
                                return "couponType", "全品"
                            } else if (d.couponType == "1") {
                                return "couponType", "单一类别"
                            }
                        }
                    },
                    {
                        field: 'useCoupon', title: '适用范围', templet: function (d) {
                            if (d.useCoupon == 0) {
                                return "useCoupon", "通用"
                            } else if (d.useCoupon == 1) {
                                return "useCoupon", "满减"
                            } else if (d.useCoupon == 2) {
                                return "useCoupon", "折扣"
                            }
                        }
                    },
                    { field: 'couponPrice', title: '优惠券金额' },
                    { field: 'couponCount', title: '发行数量' },
                    { field: 'useCount', title: '使用数量' },
                    {
                        field: 'useBeginTime', title: '开始使用时间', templet: function (d) {
                            var useBeginTime = new Date(d.useBeginTime);
                            return 'useBeginTime', top.dateFtt("yyyy-MM-dd", useBeginTime);
                        }
                    },
                    {
                        field: 'useEndTime', title: '结束使用时间', templet: function (d) {
                            var useEndTime = new Date(d.useEndTime);
                            return 'useEndTime', top.dateFtt("yyyy-MM-dd", useEndTime);
                        }
                    },

                    { title: '操作', width: 213, align: 'center', toolbar: '#barDemo' }
                ]],
                id: "idTest",
                page: true,
            });
            //监听工具条
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.get("/Reviews/Delete?id=" + data.id, function (obj, successInfo) {
                            CommonAjaxCallback(obj, function () {
                                table.reload('idTest', {
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                })
                            }, successInfo)
                        })
                        layer.close(index);
                    });
                } else if (obj.event === 'issue') {
                    top.NewTab(212, data.couponTitile + "发放优惠券", "/Coupon/Issue?id=" + data.id);
                } else if (obj.event === 'examine') {
                    top.NewTab(213, data.couponTitile + "-发放列表", "/Coupon/CouponUser?id=" + data.id);
                } else if (obj.event === 'edit') {

                    LayerOpen('修改优惠券-' + data.couponTitile, '/Coupon/Edit?id=' + data.id)
                }
            });
            $('#search').on('click', function () {
                table.reload('idTest', {
                    where: {
                        keyword: $('#keyword').val(),
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            })

            $(".layer-open").on('click', function () {
                layer.closeAll();
                layer.msg('加载中', {
                    icon: 16
                    , shade: 0.01
                });
                var url = $(this).data('url');
                var title = $(this).data('title')
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();//避免缓存
                    LayerOpen(title, url);
                }
            })


        });


        $("#layui-Area").click(function () {
            $(".layui-Area .layui-Area-hide").toggleClass("layui-Area-show")
            $(this).parent(".layui-form-select").toggleClass("layui-form-selected");
        });

        $(".layui-Area").mouseleave(function () {
            $(".layui-Area .layui-Area-hide").removeClass("layui-Area-show")
        })


        $(document).ready(function () {

        });
        var lock = false;//锁作为全局变量
        function LoadNewOpen(url) {
            if (lock) {
                return false;
            } else {
                lock = true;
            }
            $("#Layer_ajax").load(url, function (responseTxt, statusTxt, xhr) {
                if (statusTxt == "error") {
                    top.layer.msg('页面加载失败！', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }
                form.render('select')
                var uploadInst = upload.render({
                    elem: '#b_piclogo' //绑定元素
                    , url: '/Brands/UpLoadBarand' //上传接口
                    , done: function (res) {
                        if (res.success) {
                            var img = "@WebRootUrl.WebImageRootUrl()/uploads/temp/brand/";
                            $('#BrandLogo').val(res.result)
                            $('#piclogoImg').attr("src", img + res.result)
                        }
                    }
                    , error: function () {
                        //请求异常回调
                    }
                });
                $.validator.unobtrusive.parse(this);
                var height = $("#Layer_ajax").height();
                layer.open({
                    type: 1,
                    shadeClose: true,
                    title: false,
                    closeBtn: 0,
                    scrollbar: false,
                    content: $("#Layer_ajax"),
                    area: ["600px", height],
                    success: function (layero, index) {
                        //锁关闭
                        lock = false;
                    },
                    end: function () {
                        $("#Layer_ajax").empty();
                    }
                })
            })
        }

        function LayerOpen(title, url) {
            var open = layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['600px', '450px'],
                content: url,
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index)//确定两个页面的父子关系
                },
                end: function () {
                    //销毁后重新加载
                    table.reload('idTest', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    })
                }
            });
        }
        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            }, successInfo)
        }


                    //$(".layui-content").on("click", ".layer-load-new", function () {

                    //});
    </script>
}